Weave Library
The Weave library is intended to make the creation of webpages very simple. It provides valuesversion, BEGIN, TAG, CLASS, STYLE, SET, REM, CLEAN, PATH, LIST
The value version is simply a string giving the version number.
BEGIN is a function returning a rope, that is to say a tree whose leaves are strings, or, if you prefer, a string with holes (for putting tags in),
doc = BEGIN (title, stylefiles, target)The last two arguments are optional. The first argument should should be string, the document's title. The second argument must be a rope, giving a list of pathnames of CSS stylefiles relative to the target, the third argument. This must also be a string giving the pathname of the file to which Weave will write out the document when the expression
doc:END (filename)is executed. Note the use of the colon. The argument to END is optional, and is only used as a fallback when the third argument to BEGIN is absent. At least one of them must be used. Between the BEGIN and the END the document can be filled by using
doc (rope_1, ... , rope_n)A rope is either a string or a sequence of ropes.
doc [[this is a string and it can cover many lines]]or
doc { rope_1; rope_2; .... }or
doc (LIST (rope_1) (rope_2) .... (rope_n) ( ))Note that LIST must be terminated by a nil argument, and that any arguments which are functions are applied to the next argument. This can be convenient, but can get you into trouble, for example if the last argument is a function. Compound expressions must be enclosed in parentheses. Typically these will be function calls where the function is defined by TAG.
TAG is a pseudotable, a Lua gadget which can be thought of as a function that uses the syntax of tables.
func = TAG[label] (attribute)This function wraps a non-nil argument in the tag given by the label, where the opening tag may contain attributes. A nil attribute is also an option. If the function's argument is nil then a monotag is returned. Lua's syntax allows us, when the label expression is a literal string that is formed of alphanumeric characters or underscores not starting with a digit, to use the dot-notation.
TAG.div ( ) [[No attributes!]]produces <div>No attributes!</div> in the final HTML, whereas
TAG.hr (CLASS.red) ( )producesthe monotag <hr class="red">
The (compound) expression CLASS [[red]] produces class="red" in the final HTML.
CLASS (ok and [[sweet]] or [[sour]])produces the sweet class when ok is non-nil and the sour one otherwise. It is hardly a likely scenario, but could be important when multiple documents are being produced.
Similarly the (compound) expression STYLE [[css-expr]] is used for embedding CSS styles within the web page.
The above functions are actually defined by
CLASS = SET.class STYLE = SET.stylefrom which the uses of the more general pseudotable SET should be apparent.
The function REM embeds comments in HTML.
The function CLEAN only takes strings as arguments. It replaces topbit-set characters by HTML entities and replaces <, > and & by <, > and & respectively.
The function PATH strips off the leaf from a RISC OS pathname. This is useful when applied to arg[0] which holds the pathname of the Lua program being executed, so that the program an use relative pathnaming.
Other attributes of a document
Besides TITLE, CSS and FILE, which can be set by the arguments to BEGIN there are:DOCTYPE, LANG, CHARSET, HEADER, BODYSTYLE, QUIETDOCTYPE should be a string. Its default value is <!DOCTYPE html>. LANG should be a string, its default value is en. CHARSET should be a string. Its default value is utf-8. The value of HEADER may be a rope. It provides additional material for putting within the head tags. BODYSTYLE may also be a rope. It gives the CSS style to be used in the body tag. Finally, QUIET is a Boolean value. When set to true. It suppresses the output of the target's pathname which confirms the success of the conversion of the Weave source to HTML.